/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * NewOrderDialog.java
 *
 * Created on 6-nov-2011, 23:29:09
 */
package nl.windesheim.archdemo.view;

import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.JSpinner;
import javax.swing.JTable;
import nl.windesheim.archdemo.presentationmodel.EditOrderDialogPresenter;

/**
 *
 * @author reindert
 */
public class EditOrderDialog extends OkCancelDialog {
   
    private EditOrderDialogPresenter presentation;
    
    /** Creates new form NewOrderDialog */
    public EditOrderDialog(JFrame parent, EditOrderDialogPresenter presentationModel, boolean modal) {
        super(parent, modal);
        this.presentation = presentationModel;      
               
        initComponents();
    }


    public void setButtonListener(ActionListener al){
        okButton.addActionListener(al);
        selectCustomerButton.addActionListener(al);
        addOrderLineButton.addActionListener(al);

    }
    
    
        
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        okButton = new javax.swing.JButton();
        cancelButton = new javax.swing.JButton();
        selectCustomerButton = new javax.swing.JButton();
        klantLabel = new javax.swing.JLabel();
        customerPanel1 = new nl.windesheim.archdemo.view.CustomerPanel();
        productLabel = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        productTable = new javax.swing.JTable();
        addOrderLineButton = new javax.swing.JButton();
        amountLabel = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        orderLabe = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        orderLineTable = new javax.swing.JTable();
        amountSpinner = new javax.swing.JSpinner();

        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                closeDialog(evt);
            }
        });

        okButton.setText("OK");
        okButton.setEnabled(false);
        okButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                okButtonActionPerformed(evt);
            }
        });

        cancelButton.setText("Cancel");
        cancelButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cancelButtonActionPerformed(evt);
            }
        });

        selectCustomerButton.setText("Selecteer");
        selectCustomerButton.setActionCommand("SelectCustomer");

        klantLabel.setText("Klant:");

        org.jdesktop.beansbinding.Binding binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, customerPanel1, org.jdesktop.beansbinding.ObjectProperty.create(), klantLabel, org.jdesktop.beansbinding.BeanProperty.create("labelFor"));
        bindingGroup.addBinding(binding);

        productLabel.setText("Product:");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, productTable, org.jdesktop.beansbinding.ObjectProperty.create(), productLabel, org.jdesktop.beansbinding.BeanProperty.create("labelFor"));
        bindingGroup.addBinding(binding);

        productTable.setModel(presentation.getProductViewModel());
        jScrollPane1.setViewportView(productTable);

        addOrderLineButton.setText("addOrderLine");

        amountLabel.setText("Aantal:");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, amountSpinner, org.jdesktop.beansbinding.ObjectProperty.create(), amountLabel, org.jdesktop.beansbinding.BeanProperty.create("labelFor"));
        bindingGroup.addBinding(binding);

        orderLabe.setText("Order:");

        binding = org.jdesktop.beansbinding.Bindings.createAutoBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, orderLineTable, org.jdesktop.beansbinding.ObjectProperty.create(), orderLabe, org.jdesktop.beansbinding.BeanProperty.create("labelFor"));
        bindingGroup.addBinding(binding);

        orderLineTable.setModel(presentation.getOrderLineTablePresenter());
        jScrollPane3.setViewportView(orderLineTable);

        amountSpinner.setModel(new javax.swing.SpinnerNumberModel(Integer.valueOf(1), Integer.valueOf(1), null, Integer.valueOf(1)));

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 640, Short.MAX_VALUE)
                    .add(customerPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 640, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(okButton, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 67, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(cancelButton))
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(klantLabel)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 504, Short.MAX_VALUE)
                        .add(selectCustomerButton))
                    .add(productLabel)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                        .add(amountLabel)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(amountSpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 83, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 375, Short.MAX_VALUE)
                        .add(addOrderLineButton)))
                .addContainerGap())
            .add(org.jdesktop.layout.GroupLayout.TRAILING, jSeparator1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 680, Short.MAX_VALUE)
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(orderLabe)
                .addContainerGap(621, Short.MAX_VALUE))
            .add(layout.createSequentialGroup()
                .addContainerGap()
                .add(jScrollPane3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 640, Short.MAX_VALUE)
                .addContainerGap())
        );

        layout.linkSize(new java.awt.Component[] {cancelButton, okButton}, org.jdesktop.layout.GroupLayout.HORIZONTAL);

        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(selectCustomerButton)
                    .add(klantLabel))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(customerPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(productLabel)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 119, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(addOrderLineButton)
                        .add(amountLabel))
                    .add(amountSpinner, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(18, 18, 18)
                .add(jSeparator1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(orderLabe)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(jScrollPane3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 197, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 35, Short.MAX_VALUE)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(cancelButton)
                    .add(okButton))
                .addContainerGap())
        );

        getRootPane().setDefaultButton(okButton);

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /** Opens the Select Customer Dialog */

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton addOrderLineButton;
    private javax.swing.JLabel amountLabel;
    private javax.swing.JSpinner amountSpinner;
    private javax.swing.JButton cancelButton;
    private nl.windesheim.archdemo.view.CustomerPanel customerPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JLabel klantLabel;
    private javax.swing.JButton okButton;
    private javax.swing.JLabel orderLabe;
    private javax.swing.JTable orderLineTable;
    private javax.swing.JLabel productLabel;
    private javax.swing.JTable productTable;
    private javax.swing.JButton selectCustomerButton;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

  
     public CustomerPanel getCustomerPanel() {
        return customerPanel1;
    }
    
    public void setOkEnabled(){
        this.okButton.setEnabled(true);
    }
 
    public JTable getProductTable() {
        return productTable;
    }

    public JSpinner getAmountSpinner() {
        return amountSpinner;
    }

    public JTable getOrderLineTable() {
        return orderLineTable;
    }

    public EditOrderDialogPresenter getModel() {
        return presentation;
    }
    
    

}
